<?php

/**
 * @author PHATPHAM
 * @copyright 2013
 */
class SurveyTypemodel extends CI_Model {
    var $survey_type_id;    //stid
    var $survey_type_name;  //stname
    var $is_deleted;
    var $created_by_user_id;    //userid
    var $created_on_date;
    var $last_modified_by_user_id;
    var $last_modified_on_date; //userid
    
    function __construct()
    {
        // Call the Model constructor
        $this->load->database();
        $this->load->helper('date'); //Load helper date
    }
    
    //get all survey types list
    function get_survey_types_list()
    {
        $query = $this->db->get_where('sur_survey_type', array('is_deleted' => false));
        return $query;
    }
    //get 1 survey type
    function get_survey_type($stid)
    {
        $query = $this->db->get_where('sur_survey_type', array('survey_type_id' => $stid, 'is_deleted' => false));
        if($query->num_rows() > 0){
            return $query->row();
        }
        return null;
    }
    //create 1 survey type
    function create_survey_type($stid, $stname, $userid)
    {
        $this->survey_type_id = $stid;
        $this->survey_type_name = $stname; 
        $this->is_deleted = false;
        $this->created_by_user_id = $userid;
        $this->created_on_date = mdate('%m/%d/%Y %H:%i:%s',now());
        $this->db->insert('sur_survey_type', $this);
    }
    //edit 1 survey type
    function edit_survey_type($stid, $stname, $userid)
    {
        $data = array(
               'survey_type_name' => $stname,
               'last_modified_by_user_id' => $userid,
               'last_modified_on_date' => mdate('%m/%d/%Y %H:%i:%s',now())
            );
        $this->db->where('survey_type_id', $stid);
        $this->db->update('sur_survey_type', $data);
    }
    //delete 1 survey type
    function delete_survey_type($stid, $userid) 
    {
        $data = array(
               'is_deleted' => true,
               'last_modified_by_user_id' => $userid,
               'last_modified_on_date' => mdate('%m/%d/%Y %H:%i:%s',now())
            );
        $this->db->where('survey_type_id', $stid);
        $this->db->update('sur_survey_type', $data);
    }
}
?>